package com.tigerlee.stopmusic;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class MyPreference {
	public static final String KEY_IS_RUNNING = "is_running";
	public static final String KEY_IS_SETTIME = "timer_state";
	public static final String KEY_START_TIME = "start_time";
	public static final String KEY_STOP_TIME = "stop_time";
	public static final String KEY_WIDGET_ALARM = "widget_time";
	
	public static final String KEY_TURNOFF_MUSIC = "turnoff_music";
	public static final String KEY_TURNOFF_BLUETOOTH = "turnoff_bluetooth";
	public static final String KEY_TURNOFF_WIFI = "turnoff_wifi";

	public static SharedPreferences mPreference;

	public MyPreference(Context context) {
		mPreference = PreferenceManager.getDefaultSharedPreferences(context);
	}

	public void initPreference() {
		SharedPreferences.Editor editor = mPreference.edit();
		editor.putBoolean(KEY_IS_RUNNING, false);
		editor.putLong(KEY_START_TIME, 0);
		editor.putLong(KEY_STOP_TIME, 0);
		editor.putInt(KEY_WIDGET_ALARM, 10);
		editor.putBoolean(KEY_TURNOFF_MUSIC, false);
		editor.putBoolean(KEY_TURNOFF_BLUETOOTH, false);
		editor.putBoolean(KEY_TURNOFF_WIFI, false);
		editor.commit();
	}
	
	public boolean isRunning() {
		return mPreference.getBoolean(KEY_IS_RUNNING, false);
	}

	public void setRunningState(boolean state) {
		SharedPreferences.Editor editor = mPreference.edit();
		editor.putBoolean(KEY_IS_RUNNING, state);
		editor.commit();
	}
	
	public boolean getTimerState() {
		return mPreference.getBoolean(KEY_IS_SETTIME, false);
	}

	public void setTimerState(boolean state) {
		SharedPreferences.Editor editor = mPreference.edit();
		editor.putBoolean(KEY_IS_SETTIME, state);
		editor.commit();
	}
	
	public long getStartTime() {
		long startTime = mPreference.getLong(KEY_START_TIME, 0);
		return startTime;
	}

	public void setStartTime(long startTime) {
		SharedPreferences.Editor editor = mPreference.edit();
		editor.putLong(KEY_START_TIME, startTime);
		editor.commit();
	}

	public long getStopTime() {
		long stopTime = mPreference.getLong(KEY_STOP_TIME, 0);
		return stopTime;
	}

	public void setStopTime(long stopTime) {
		SharedPreferences.Editor editor = mPreference.edit();
		editor.putLong(KEY_STOP_TIME, stopTime);
		editor.commit();
	}
	public int getWidgetTime(){
		int widgetTime = mPreference.getInt(KEY_WIDGET_ALARM, 10);
		return widgetTime;
	}
	
	public void setWidgetTime(int widgetTime){
		SharedPreferences.Editor editor = mPreference.edit();
		editor.putInt(KEY_WIDGET_ALARM, widgetTime);
		editor.commit();
	}
	
	public boolean isTurnOffMusic(){
		boolean isTurnoffMusic = mPreference.getBoolean(KEY_TURNOFF_MUSIC, false);
		return isTurnoffMusic;
	}
	
	public void setTurnOffMusic(boolean isTurnOffMusic){
		SharedPreferences.Editor editor = mPreference.edit();
		editor.putBoolean(KEY_TURNOFF_MUSIC, isTurnOffMusic);
		editor.commit();
	}
	
	public boolean isTurnOffBluetooth(){
		boolean isTurnoffMusic = mPreference.getBoolean(KEY_TURNOFF_BLUETOOTH, false);
		return isTurnoffMusic;
	}
	
	public void setTurnOffBluetooth(boolean isTurnOffBluetooth){
		SharedPreferences.Editor editor = mPreference.edit();
		editor.putBoolean(KEY_TURNOFF_BLUETOOTH, isTurnOffBluetooth);
		editor.commit();
	}
	
	public boolean isTurnOffWifi(){
		boolean isTurnoffMusic = mPreference.getBoolean(KEY_TURNOFF_WIFI, false);
		return isTurnoffMusic;
	}
	
	public void setTurnOffWifi(boolean isTurnOffWifi){
		SharedPreferences.Editor editor = mPreference.edit();
		editor.putBoolean(KEY_TURNOFF_WIFI, isTurnOffWifi);
		editor.commit();
	}
}
